//
// Created by RandBII on 2020/12/24.
//

#include <malloc.h>
#include <cstring>
#include "AudioFrame.h"

AudioFrame::~AudioFrame() {
    if (hardCopy && this->data) {
        free(this->data);
    }
    this->data = nullptr;
}

AudioFrame::AudioFrame(uint8_t *data, int dataSize, bool hardCopy) {
    this->data = data;
    this->dataSize = dataSize;
    this->hardCopy = hardCopy;
    if (hardCopy) {
        this->data = static_cast<uint8_t *>(malloc(this->dataSize));
        memcpy(this->data, data, dataSize);
    }
}
